package com.entor.controller;

import java.awt.Menu;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.entor.model.EduMenu;
import com.entor.model.EduRoleMenu;
import com.entor.model.Role;
import com.entor.service.RoleService;
import com.entor.util.Msg;
import com.entor.util.StringUtil;

@Controller
@RequestMapping("/role")
public class RoleController extends BaseController{

	@Resource(name="roleService")
	private RoleService rs;
	
	@RequestMapping("/index")
	public String roleIndex(){
		return "/role/roleIndex";
	}
	
	@RequestMapping("/find")
	@ResponseBody
	public List<Role> find(Role t){
		return rs.find(t);
	}
	
	@RequestMapping("/add")
	@ResponseBody
	public Msg add(Role t){
		return rs.add(t);
	}
	@RequestMapping("/edit")
	@ResponseBody
	public Msg edit(Role t){
		return rs.edit(t);
	}
	@RequestMapping("/remove/{id}")
	@ResponseBody
	public Msg remove(@PathVariable(value="id") int id){
		return rs.remove(id);
	}
	
	@RequestMapping("/grant")
	@ResponseBody
	public Msg grant(HttpServletRequest req){
		String rid = req.getParameter("rid");
		String mids = req.getParameter("mids");
		
		return rs.roleGrant(rid, mids);
	}
	
	@RequestMapping("/findRoleMenu/{rid}")
	@ResponseBody
	public List<EduRoleMenu> findRoleMenu(
			@PathVariable(value="rid") int rid){
		return rs.findRoleMenu(rid);
	}
	
	@RequestMapping("/getMenu/{rid}")
	@ResponseBody
	public String getMenu(@PathVariable(value="rid") int rid){
		List<EduMenu> list = rs.getMenu(rid);
		return StringUtil.createMenu(list);
	}
	
	
	
	
	
	
	
	
}
